
/*
*Released on 28th June 2008.
*Any violations can be reported at paritosh@wikiocean.net
*What is treated as violations can be found at www.wikiocean.net/ppl1-voilations*
******************************************************************************
* The contents of this file are subject to POOL Public License 1.0 and later.
* POOL Public License is based on Affero GPL v3 and additional conditions.
* ("License"); You may not use this file except in compliance with the License
* You may obtain a copy of the Affero GPL v3 License at http://www.gnu.org/licenses/agpl.html
* You may obtain a copy of the POOL Public License 1.0 or later at www.wikiocean.net/license/ppl.html
* Software distributed under POOL Public License 1.0 is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
* the specific language governing rights and limitations under the License.
* The Initial Developer of the Original Code is Paritosh Pungaliya (C) 2008. All Rights Reserved.
******************************************************************************
* Objective of the additional terms (license)
* 1) Is to extend the software freedom to freedom to work.
* 2) To ensure that knowledge is free from monopoly of agencies.
* 3) To avoid a situation where big corporate or investor can buy out free software groups and companies and then start milking the communities built around it.
* (this trend can be seen how the freedom is curtailed in companies that get Venture Capital funding.)
******************************************************************************
*/

package  basicprocess.inheritance;

import java.util.Hashtable;
import java.util.LinkedList;
import java.util.Map;
import java.util.Vector;

import pool.tablename.Property_details;
import pool.tablename.Pool;


import utility.ConvertToLower;
import utility.Input;

import dbmanager.DBManager;
import dbmanager.GetIdName;
import file.SearchRecord;

public class Iu implements Inheritance 
{
	DBManager database;
	Hashtable<Object, Object>Mastermap= new Hashtable<Object, Object>();
	Vector< Object>propertyVector = new Vector<Object>();
	GetIdName gid;
	String INHERITANCE="inheritance";
	String SCOPE="scope";
	String IU="iu";
	Pool pool;
	SearchRecord sr;
	Vector<Object>finalvector = new Vector<Object>();

	public void getInsert()
	{
		LinkedList<Object>  linkedlist = new LinkedList<Object>();
		
		for(int i=0;i<pool.getpropertyVector().size();i++)
		{
			Hashtable<Object, Object> table = new Hashtable<Object, Object>();
			table.putAll((Map<? extends Object, ? extends Object>) pool.getpropertyVector().get(i));
			if(!table.get("pid").equals(INHERITANCE))
			{
				linkedlist.add(table.get("pid"));
				//pdobject.PropertyMap.clear();
				finalvector.add(table);
			}
		}
		for(int i=0;i<pool.getpropertyVector().size();i++)
		{
			Property_details pd = (Property_details)pool.getpropertyVector().get(i);
			try
			{	
				if(pd.PropertyMap.get("pid").equals(INHERITANCE))
				{
					String parentobject = pd.PropertyMap.get("pv").toString();
					Vector<Object> vector = new Vector<Object>();
					Hashtable<Object, Object>temptable = new Hashtable<Object, Object>();
					String path = Input.MASTERREPORTSPATH + parentobject +"//"+ parentobject + "_mid" + Input.FILRFORMAT;
					sr = new SearchRecord(path);
					sr.fileOpen();
					temptable.put("mid", parentobject);
					vector = sr.getVectorSet(temptable);
					sr.fileClose();
					Scope scope = new Scope();
					scope.InitPool();
					vector = scope.checkforscope(vector,parentobject);
					System.out.println(pd.PropertyMap);
					finalvector.add(pd);
					Hashtable<Object, Object> table = new Hashtable<Object, Object>();
					for(int j=0;j<vector.size();j++)
					{
						temptable.clear();
						temptable = (Hashtable<Object, Object>) vector.get(j);
						temptable = ConvertToLower.convertHashKey(temptable);
						String propertyid =temptable.get("pid").toString();
						if(!linkedlist.contains(propertyid))
						{	
							if(temptable.containsKey("mid"))
								temptable.remove("mid");
							table.putAll(temptable);
							finalvector.add(table);
							//System.out.println(pdobject.PropertyMap);
						}	
					}
					break;	//MARUTEE
				}
			}
			catch (Exception e) 
			{
				e.printStackTrace();
			}
		}
		pool.setPropertyVector(finalvector);
	}

	public void getUpdate() 
	{	
		for(int i=0;i<pool.getpropertyVector().size();i++)
		{
			Property_details pd = (Property_details) pool.getpropertyVector().get(i);
			pd.PropertyMap = gid.convertMasterName(pd.PropertyMap, "property_details");
		}
	}

	public Vector<Object> getpropertydetailsVector() 
	{
		return null;
	}

	public void InitPool() 
	{	
		gid = new GetIdName();
		INHERITANCE = gid.getId(INHERITANCE);
		SCOPE = gid.getId(SCOPE);
		IU = gid.getId(IU);
		
	}

	public void setobject(Object object) 
	{
		pool = (Pool) object;
	}

}
